package com.example.human_resource_management.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.human_resource_management.entry.dto.AdminLoginDto;
import com.example.human_resource_management.entry.dto.AdminUpdateDto;
import com.example.human_resource_management.entry.po.Admin;
import com.example.human_resource_management.mapper.AdminMapper;
import com.example.human_resource_management.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin login(AdminLoginDto adminLoginDto) {
        return adminMapper.findAdminByAccountAndPassword(
                adminLoginDto.getAccount(),
                adminLoginDto.getPassword()
        );
    }
    @Override
    public List<Admin> getAllAdmins() {
        // 使用MyBatis Plus的selectList方法查询所有
        return this.list();
    }

    @Override
    public boolean updateAdmin(AdminUpdateDto updateDto) {
        // 构建更新对象
        Admin admin = new Admin();
        admin.setAdminId(updateDto.getAdminId());
        admin.setName(updateDto.getName());
        admin.setAccount(updateDto.getAccount());
        admin.setPassword(updateDto.getPassword());
        admin.setRole(updateDto.getRole());

        // 执行更新
        return this.updateById(admin);
    }
}